-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: moving cli config to --set for nodeport and storageclass #2083
Conversation
✅ Deploy Preview for zarf-docs canceled.
|
…till be there, just not in the output
…nd removed from the zarf init --help
…e main init options
…e the cluster's default storage class. This should be backwards compatible with any deployment that is using the default storage class, without having to put it into zarf state
…appears to work better
…d needs a refactor later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more consistent with other deprecated fields/flags in the codebase, it would probably be good to rename the deprecated fields to DeprecatedStorageClass
in the ZarfInitOptions
struct, and DeprecatedNodePort
in the RegistryInfo
struct. This way we wouldn't need to add the nodePortArg
and storageClassArg
variables or remove any struct fields at this time.
|
||
if internalRegistry { | ||
if configuredNodePort > 32767 || configuredNodePort < 30000 { | ||
configuredNodePort = config.ZarfInClusterContainerRegistryNodePort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would probably be good to notify the user that they provided an invalid nodeport number and that we're going to use the default Zarf nodeport of 31999
instead. Might save users some confusion on why their specified port number wasn't used by Zarf.
pkgConfig.InitOpts.RegistryInfo.NodePort = configuredNodePort | ||
} else { | ||
// do not set the nodeport if this is an external registry | ||
pkgConfig.PkgOpts.SetVariables[configVar] = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to remove this else block. If the user specifies an external registry, we shouldn't have to set the REGISTRY_NODEPORT
var to an empty string
storageClassArg = "" | ||
setRegistryStorageClass() | ||
if storageClassArg != "test-storage-class" { | ||
t.Errorf("Expected storage class to be set to 'test-storage-class', but got '%s'", storageClassArg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use require.Equal()
to be more consistent with the rest of our test suite assertions. When require.Equal()
fails it prints an "expected but got" message by default for you.
storageClassArg = "old-storage-class" | ||
setRegistryStorageClass() | ||
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "old-storage-class" { | ||
t.Errorf("Expected storage class to be set to old way value, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use require.Equal()
to be more consistent with the rest of our test suite assertions. When require.Equal()
fails it prints an "expected but got" message by default for you.
storageClassArg = "" | ||
setRegistryStorageClass() | ||
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "" { | ||
t.Errorf("Expected storage class to be set to empty string, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use require.Equal()
to be more consistent with the rest of our test suite assertions. When require.Equal()
fails it prints an "expected but got" message by default for you.
} | ||
|
||
if err != nil { | ||
message.WarnErr(err, "Unable to get the default storage class from the cluster") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have an opportunity to fail fast here. If REGISTRY_PVC_ENABLED
is true (this is the default), the user did not specify a storage class to use, and there was no default storage class found in the cluster, we should fail fast and notify the user that a storage class is needed for the registry to deploy successfully.
RKE2 clusters come to mind since they don't provide a default storage class
@@ -1,5 +1,5 @@ | |||
persistence: | |||
storageClass: "###ZARF_STORAGE_CLASS###" | |||
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###" | |
storageClass: "###ZARF_VAR_GIT_SERVER_STORAGE_CLASS###" |
default: "31999" | ||
autoIndent: true | ||
|
||
- name: REGISTRY_STORAGE_CLASS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a corresponding variable for the GIT_SERVER
|
||
// DEPRECATED_V1.0.0: --storage-class should be removed from the CLI in v1.0.0 | ||
func setRegistryStorageClass() { | ||
configVar := "REGISTRY_STORAGE_CLASS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would set both the registry and git server vars
// Zarf CLI deprecation warnings | ||
const ( | ||
// remove deprecation in v1.0.0 | ||
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>" | |
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value> and --set GIT_SERVER_STORAGE_CLASS=<value>" |
|
||
pkgConfig.InitOpts.RegistryInfo.InternalRegistry = internalRegistry | ||
|
||
// TODO: test external registry and CLI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo
@@ -167,7 +174,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA | |||
CmdInitFlagGitPullPass = "Password for the pull-only user to access the git server" | |||
|
|||
CmdInitFlagRegURL = "External registry url address to use for this Zarf cluster" | |||
CmdInitFlagRegNodePort = "Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]" | |||
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]" | |
CmdInitFlagRegNodePort = "[Deprecated] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767] (use --set REGISTRY_NODEPORT=<value> instead)" |
p.cfg.PkgOpts.SetVariables = map[string]string{} | ||
} | ||
if c := p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"]; c == "" { | ||
p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"], err = p.cluster.GetDefaultStorageClass() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed if the storage class is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this with k3d
, kind
, k3s
, and minikube
locally across zarf v0.31.3 and this build, new inits and upgrades... do you have a test case where this was needed?
if newState.RegistryInfo.Address == fmt.Sprintf("%s:%d", helpers.IPV4Localhost, newState.RegistryInfo.NodePort) { | ||
newState.RegistryInfo.InternalRegistry = true | ||
} else { | ||
newState.RegistryInfo.InternalRegistry = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this logic from here will break the library usages of zarf init
- Nodeport should be pulled out of ZARF_VAR_REGISTRY_NODEPORT for now. (later this can be refactored to a more explicit mapping)
if values.config.SetVariableMap != nil { | ||
if regInfo.NodePort > 0 && values.config.SetVariableMap["REGISTRY_NODEPORT"] != nil { | ||
values.config.SetVariableMap["REGISTRY_NODEPORT"].Value = fmt.Sprintf("%d", regInfo.NodePort) | ||
} | ||
if values.config.State.StorageClass != "" && values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"] != nil { | ||
values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"].Value = values.config.State.StorageClass | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be here - variables in a zarf.yaml will just pass through
// removed | ||
//StorageClass string `json:"storageClass" jsonschema:"description=StorageClass of the k8s cluster Zarf is initializing"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code should be deleted - it will still be in git if we ever need it
Closing this PR because we will likely rethink the implementation |
Description
replace -nodeport and --storageclass:
zarf init --nodeport <number> --storage-class <my-storage-class>
with:
zarf init --set REGISTRY_NODEPORT=31998 --set REGISTRY_STORAGE_CLASS=my-storage-class
old variables still exist and work, but warnings are given to the user if they use them as deprecated.
NOTE:
storageClass to be used for gitea and the registry will by default be the default storageClass of the cluster.
Related Issue
Fixes #1725
Type of change
Checklist before merging